package cdc.rxjava2.demo;

import io.reactivex.Flowable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

public class MapOperator2 {
	/**
	 * 
	 * map 是把传递过来的结果末尾加上了签名，然后在传递给了订阅者.
	 * 
	 * map的作用就变换 Flowable 然后返回一个指定类型的 Flowable 对象。
	 * 
	 * 
	 * */
	public MapOperator2() {
		Flowable.just("map2")
	    .map(new Function<String, Integer>() {
	        @Override
	        public Integer apply(String s) throws Exception {
	        	System.out.println("s="+s);
	            return s.hashCode();
	        }
	    })
	    .map(new Function<Integer, String>() {
	        @Override
	        public String apply(Integer integer) throws Exception {
	        	System.out.println("integer="+integer);
	            return integer.toString();
	        }
	    })
	    .subscribe(new Consumer<String>() {
	        @Override
	        public void accept(String s) throws Exception {
	            System.out.println(s);
	        }
	    });
	}
}
